package backend.project.gym_management.service.impl;

import backend.project.gym_management.mapper.CoachMapper;
import backend.project.gym_management.pojo.entity.CoachIntroduction;
import backend.project.gym_management.pojo.entity.Course;
import backend.project.gym_management.pojo.entity.CourseIntroduction;
import backend.project.gym_management.pojo.vo.CoachCourseVO;
import backend.project.gym_management.pojo.vo.CoachEnrollmentVO;
import backend.project.gym_management.pojo.vo.CoachIntroductionVO;
import backend.project.gym_management.pojo.vo.UserHealthDataVO;
import backend.project.gym_management.service.CoachService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CoachServiceImpl implements CoachService {
    @Autowired
    private CoachMapper coachMapper;
    @Override
    public List<CoachCourseVO> listCourse(Long eid){
        var data = coachMapper.selectCourseByEid(eid);
        log.debug(String.valueOf(data.get(0).getFullPrice()));
        return data;
    }
    @Override
    public int addCourse(Course course) {
        return coachMapper.insertCourse(course);
    }
    @Override
    public CourseIntroduction selectCourseIntroduction(Long cid){
        return coachMapper.selectCourseIntroductionByCid(cid);
    }
    @Override
    public int addCourseIntroduction(CourseIntroduction courseIntroduction) {
        return coachMapper.insertCourseIntroduction(courseIntroduction);
    }
    @Override
    public int updateCourseIntroduction(CourseIntroduction courseIntroduction){
        return coachMapper.updateCourseIntroduction(courseIntroduction);
    }
    @Override
    public List<CoachEnrollmentVO> listEnrollmentVO(Long cid) throws Exception {
        var result = coachMapper.selectEnrollmentByCid(cid);
        if (result.isEmpty()) throw new Exception("查询学员名单失败");
        return result;
    }
    @Override
    public UserHealthDataVO selectUserHealthByUid(Long uid) throws Exception {
        var result = coachMapper.selectUserHealthByUid(uid);
        if (result==null) throw new Exception("查询学员健康失败");
        return result;
    }

    @Override
    public CoachIntroductionVO selectCoachIntroductionByEid(Long eid) {
        return coachMapper.selectCoachIntroductionByEid(eid);
    }

    @Override
    public int addCoachIntroduction(CoachIntroduction coachIntroduction) throws Exception {
        var result = coachMapper.insertCoachIntroduction(coachIntroduction);
        if (result==0) throw new Exception("添加教练简历失败");
        return result;
    }

    @Override
    public int updateCoachIntroduction(CoachIntroduction coachIntroduction) throws Exception {
        var result = coachMapper.updateCoachIntroduction(coachIntroduction);
        if (result==0) throw new Exception("修改教练简历失败");
        return result;
    }
}
